/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package domen;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Danilo
 */
@Entity
@Table(name = "application")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Application.findAll", query = "SELECT a FROM Application a"),
    @NamedQuery(name = "Application.findByApplicationId", query = "SELECT a FROM Application a WHERE a.applicationId = :applicationId"),
    @NamedQuery(name = "Application.findByName", query = "SELECT a FROM Application a WHERE a.name = :name"),
    @NamedQuery(name = "Application.findByMinAndReq", query = "SELECT a FROM Application a WHERE a.minAndReq = :minAndReq"),
    @NamedQuery(name = "Application.findByDownloads", query = "SELECT a FROM Application a WHERE a.downloads = :downloads"),
    @NamedQuery(name = "Application.findByRating", query = "SELECT a FROM Application a WHERE a.rating = :rating"),
    @NamedQuery(name = "Application.findByEnabled", query = "SELECT a FROM Application a WHERE a.enabled = :enabled")})
public class Application implements Serializable {
    @Basic(optional = false)
    @NotNull
    @Lob
    @Column(name = "image1")
    private byte[] image1;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Column(name = "image2")
    private byte[] image2;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Column(name = "apkFile")
    private byte[] apkFile;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "applications")
    private List<Downloadinfo> downloadinfoList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "applicationId")
    private int applicationId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 2147483647)
    @Column(name = "description")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(name = "minAndReq")
    private String minAndReq;
    @Basic(optional = false)
    @NotNull
    @Column(name = "downloads")
    private int downloads;
    @Basic(optional = false)
    @NotNull
    @Column(name = "rating")
    private double rating;
    @Basic(optional = false)
    @NotNull
    @Column(name = "enabled")
    private boolean enabled;
    @JoinColumn(name = "user", referencedColumnName = "username")
    @ManyToOne(optional = false)
    private User user;

    public Application() {
    }

    public Application(int applicationId) {
        this.applicationId = applicationId;
    }

    public Application(int applicationId, String name, String description, byte[] image1, byte[] image2, byte[] apkFile, String minAndReq, int downloads, double rating, boolean enabled) {
        this.applicationId = applicationId;
        this.name = name;
        this.description = description;
        this.image1 = image1;
        this.image2 = image2;
        this.apkFile = apkFile;
        this.minAndReq = minAndReq;
        this.downloads = downloads;
        this.rating = rating;
        this.enabled = enabled;
    }

    public int getApplicationId() {
        return applicationId;
    }

    public void setApplicationId(int applicationId) {
        this.applicationId = applicationId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getMinAndReq() {
        return minAndReq;
    }

    public void setMinAndReq(String minAndReq) {
        this.minAndReq = minAndReq;
    }

    public int getDownloads() {
        return downloads;
    }

    public void setDownloads(int downloads) {
        this.downloads = downloads;
    }

    public double getRating() {
        return rating;
    }

    public void setRating(double rating) {
        this.rating = rating;
    }

    public boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Application)) {
            return false;
        }
        Application other = (Application) object;
        if (this.applicationId != other.applicationId) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return name;
    }

    public byte[] getImage1() {
        return image1;
    }

    public void setImage1(byte[] image1) {
        this.image1 = image1;
    }

    public byte[] getImage2() {
        return image2;
    }

    public void setImage2(byte[] image2) {
        this.image2 = image2;
    }

    public byte[] getApkFile() {
        return apkFile;
    }

    public void setApkFile(byte[] apkFile) {
        this.apkFile = apkFile;
    }

    @XmlTransient
    public List<Downloadinfo> getDownloadinfoList() {
        return downloadinfoList;
    }

    public void setDownloadinfoList(List<Downloadinfo> downloadinfoList) {
        this.downloadinfoList = downloadinfoList;
    }
}
